<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>列表页</title>
    <link rel="stylesheet" href="common.css" />
    <link rel="stylesheet" href="list.css" />
    <!-- 引入jQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
  </head>
  <body>
    <div class="navigation">
      <!-- 头像 -->
      <img src="病人.png" alt="病人" />
      <div class="title">我的博客系统</div>

      <div class="space"></div>

      <a href="blog_list.html">主页</a>
      <a href="blog_edit.html">写博客</a>
      <a href="logout">退出登录状态</a>
    </div>

    <!-- 页面主体 -->
    <div class="container">
      <div class="container-left">
        <div class="card">
          <img src="病人.png" alt="病人" />
          <h3></h3>
          <a target="_blank" href="https://gitee.com/carefree-state"
            >我的码云链接</a
          >
          <div class="counter">
            <span class="h">文章</span>
            <span class="h">分类</span>
          </div>

          <div class="counter">
            <span id="count">3</span>
            <span>1</span>
          </div>
        </div>
      </div>

      <div class="container-right">
        <div class="article"></div>
      </div>
    </div>
    <script>
      jQuery.ajax({
        type:"get",
        url:"login",
        success: function(body) {
          jQuery(".card h3").text(body.username);
          jQuery(".card img").attr("src", body.image);
          jQuery(".card a").attr("href", body.git);
        },
        error: function(body) {
          location.href = "blog_login.html";
        }
      });
      function getBlogs() {
        jQuery.ajax({
          type: "get",
          url: "blog",
          success: function (body) {
            //body直接用
            var count = 0;
            for (var blog of body) {
              var aBlog = jQuery("<div></div>");
              aBlog.attr("class", "blog");
              var aTitle = jQuery("<div></div>");
              aTitle.attr("class", "title");
              aTitle.text(blog.title);
              var aDate = jQuery("<div></div>");
              aDate.attr("class", "date");
              aDate.text(blog.postTime);
              var aContent = jQuery("<div></div>");
              aContent.attr("class", "content");
              aContent.text(blog.content);
              var aA = jQuery("<a></a>");
              aA.attr("href", "blog_detail.html?blogId=" + blog.blogId);
              aA.text("查看全文");
              aBlog.append(aTitle);
              aBlog.append(aDate);
              aBlog.append(aContent);
              aBlog.append(aA);
              jQuery(".article").append(aBlog);
              count++;
            }
            jQuery("#count").text(count);
          },
        });
      }
      getBlogs();
    </script>
  </body>
</html>
